package cn.iocoder.yudao.module.yyzx.service.nurse_content;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_content.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_content.Nurse_contentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.nurse_content.Nurse_contentMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 护理内容 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class Nurse_contentServiceImpl implements Nurse_contentService {

    @Resource
    private Nurse_contentMapper nurse_contentMapper;

    @Override
    public Integer createNurse_content(Nurse_contentSaveReqVO createReqVO) {
        // 插入
        Nurse_contentDO nurse_content = BeanUtils.toBean(createReqVO, Nurse_contentDO.class);
        nurse_contentMapper.insert(nurse_content);
        // 返回
        return nurse_content.getId();
    }

    @Override
    public void updateNurse_content(Nurse_contentSaveReqVO updateReqVO) {
        // 校验存在
        validateNurse_contentExists(updateReqVO.getId());
        // 更新
        Nurse_contentDO updateObj = BeanUtils.toBean(updateReqVO, Nurse_contentDO.class);
        nurse_contentMapper.updateById(updateObj);
    }

    @Override
    public void deleteNurse_content(Integer id) {
        // 校验存在
        validateNurse_contentExists(id);
        // 删除
        nurse_contentMapper.deleteById(id);
    }

    private void validateNurse_contentExists(Integer id) {
        if (nurse_contentMapper.selectById(id) == null) {
            throw exception(NURSE_CONTENT_NOT_EXISTS);
        }
    }

    @Override
    public Nurse_contentDO getNurse_content(Integer id) {
        return nurse_contentMapper.selectById(id);
    }

    @Override
    public PageResult<Nurse_contentDO> getNurse_contentPage(Nurse_contentPageReqVO pageReqVO) {
        return nurse_contentMapper.selectPage(pageReqVO);
    }

}